package org.ymjava.medical.wx.web;


import com.ace.cache.annotation.Cache;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.ymjava.medical.core.util.ResponseUtil;
import org.ymjava.medical.db.AllPackage.biz.NurseQuestionBiz;
import org.ymjava.medical.db.AllPackage.biz.PrepareForClassBiz;
import org.ymjava.medical.db.AllPackage.biz.PrepareForUserBiz;
import org.ymjava.medical.db.AllPackage.biz.QuestionBankBiz;
import org.ymjava.medical.db.AllPackage.entity.NurseQuestion;
import org.ymjava.medical.db.AllPackage.entity.PrepareForUser;
import org.ymjava.medical.db.AllPackage.entity.QuestionBank;
import org.ymjava.medical.db.AllPackage.mapper.QuestionBankMapper;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.awt.print.PrinterGraphics;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("wx_answer/prepare_for_class")
public class PrepareForClassController {

    private final Log logger = LogFactory.getLog(PrepareForClassController.class);

    @Autowired
    PrepareForClassBiz prepareForClassBiz;

    @Autowired
    QuestionBankBiz questionBankBiz;

    @Autowired
    NurseQuestionBiz nurseQuestionBiz;

    @Autowired
    PrepareForUserBiz prepareForUserBiz;

    @GetMapping("/query_count")
    public Object queryCount(Integer classId,Integer userId){
        logger.info(classId);
        logger.info(userId);

        QuestionBank bank = new QuestionBank();
        bank.setDeleted(0);
        bank.setPrepareId(classId);

        List<QuestionBank> list = questionBankBiz.selectList(bank);

        List<Integer> list_integer = new ArrayList<>();
        for(QuestionBank banked : list){
            list_integer.add(banked.getId());
        }
        System.out.println(list_integer);
        Integer count = nurseQuestionBiz.selectCountByList(list_integer);

        //查询顺序查询的位置


        List<PrepareForUser> PFU = prepareForUserBiz.queryPostion(userId,classId);

        logger.info(PFU);

        Integer true_count = 0;

        if(PFU.size() != 0){
            true_count = PFU.get(0).getPostition();
        }

        Map<String,Object> data = new HashMap<>(2);
        data.put("count",count);
        data.put("true_count",true_count);

        return ResponseUtil.ok(data);
    }

    @GetMapping("/question_list")
    public Object question_list(Integer classId, Integer typeId){

        //typeId

        QuestionBank bank = new QuestionBank();
        bank.setDeleted(0);
        bank.setPrepareId(classId);
        Map<String,Object> data = new HashMap<>(2);
        List<QuestionBank> question_list = questionBankBiz.selectList(bank);
        data.put("question_list",question_list);

        return ResponseUtil.ok(data);
    }

    @GetMapping("/question_and_option_list")
    public Object question_and_list(Integer typeId,Integer classId){

        List<NurseQuestion> list_question = nurseQuestionBiz.list_question_option(typeId,classId);

        return ResponseUtil.ok(list_question);
    }

}
